<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>添加 system 启动脚本</title>
    {% load staticfiles %}
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

    <link rel="stylesheet" href="{% static 'lib/layui/css/layui.css' %}">
    <link rel="stylesheet" href="{% static 'css/scroll-bar.css' %}">
    <link rel="stylesheet" href="{% static 'css/sub-page.css' %}">

    <link rel="stylesheet" href="//at.alicdn.com/t/font_693759_wytlyqhtdtj1nhfr.css">
</head>
<body>
<div class="ok-body">
    <!--面包屑导航区域-->
    <div class="ok-body-breadcrumb">
            <span class="layui-breadcrumb">
                <a><cite>首页</cite></a>
                <a><cite>系统推送</cite></a>
                <a><cite>system 管理</cite></a>
				<a><cite>添加system 脚本</cite></a>
            </span>
        <a class="layui-btn layui-btn-small" href="javascript:location.replace(location.href);" title="刷新">
            <i class="layui-icon layui-icon-refresh"></i>
        </a>
    </div>
    <!--form表单-->
    <form class="layui-form layui-form-pane ok-form">


        <div class="layui-form-item">
            <label class="layui-form-label">系统名称</label>
            <div class="layui-input-block">
                <input type="text" name="name" placeholder="请输入任务名称" autocomplete="off" class="layui-input"
                       lay-verify="required">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">hostname</label>
            <div class="layui-input-block">
                <input type="text" name="hostname" autocomplete="off" placeholder="请输入主机名称" class="layui-input"
                       lay-verify="required">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">interface</label>
            <div class="layui-input-block">
                <input type="text" name="interface" placeholder="请输入网卡名称" value="eth0" autocomplete="off"
                       class="layui-input"
                       lay-verify="required">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">ip_address</label>
            <div class="layui-input-block">
                <input type="text" name="ip_address" autocomplete="off" placeholder="请输入IP地址" class="layui-input"
                       lay-verify="ip_address">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">netmask</label>
            <div class="layui-input-block">
                <input type="text" name="netmask" autocomplete="off" placeholder="请输入子网掩码" value="255.255.255.0"
                       class="layui-input"
                       lay-verify="ip_address">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">gateway</label>
            <div class="layui-input-block">
                <input type="text" name="gateway" autocomplete="off" placeholder="请输入网关" class="layui-input"
                       lay-verify="ip_address">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">DNS</label>
            <div class="layui-input-block">
                <input type="text" name="name_servers" autocomplete="off" placeholder="请输入DNS地址" value="114.114.114.114"
                       class="layui-input"
                       lay-verify="ip_address">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">MAC</label>
            <div class="layui-input-block">
                <input type="text" name="mac_address" autocomplete="off" placeholder="请输入MAC地址"
                       class="layui-input"
                       lay-verify="mac_address">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">kickstart</label>
            <div class="layui-input-block">
                <select name="kickstart" lay-filter="loginuser">
                    <option value=""></option>
                    <option value="" selected=""></option>
                    {% for ks in kickstart %}
                        <option value="{{ ks.kickstart }}">{{ ks.kickstart }} --> {{ ks.status }}</option>
                    {% endfor %}
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">profile</label>
            <div class="layui-input-block">
                <select name="profile" lay-filter="loginuser">
                    <option value=""></option>
                    <option value="" selected=""></option>
                    {% for pe in profile %}
                        <option value="{{ pe }}">{{ pe }}</option>
                    {% endfor %}
                </select>
            </div>
        </div>
            <div class="layui-form-item">
            <label class="layui-form-label">网络启动</label>
            <div class="layui-input-block">
                <input type="checkbox" name="netboot_enabled" lay-skin="switch" lay-text="启用|禁用" checked value="0">
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="add">添加</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>
<!--js逻辑-->
<script src="{% static 'lib/layui/layui.js' %}"></script>
<script>
    layui.use(['element', 'form', 'jquery', 'laydate'], function () {
        var element = layui.element;
        var table = layui.table;
        var form = layui.form;
        var $ = layui.jquery;
        var laydate = layui.laydate;

        laydate.render({
            elem: '#birthday',
            type: "datetime"
        });
         form.verify({
            mac_address: function (value, item) {
                var temp = /^([A-Fa-f0-9]{2}:[A-Fa-f0-9]{2}:[A-Fa-f0-9]{2}:[A-Fa-f0-9]{2}:[A-Fa-f0-9]{2}:[A-Fa-f0-9]{2})$/;
                if (!temp.test(value)) {
                    return '请输入正确的mac地址,mac 以 : 分割';
                }
            }
            , ip_address: function (value, item) {
                var re = /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/;
                if (!re.test(value)) {
                    return '请输入正确的ip地址';
                }
            },

        });
        form.on('submit(add)', function (data) {
            console.log(data.field);

            $.ajax({
                type: 'post',
                url: "{% url 'api_init_system_system_add' %}", // ajax请求路径
                data: {
                    data: JSON.stringify(data.field),
                    csrfmiddlewaretoken: "{{ csrf_token }}",
                },
                dataType: 'json',
                success: function (data) {
                    if (data["status"] == 0) {
                        layer.msg(data["message"], {icon: 6, time: 1000, anim: 4}, function () {
                            parent.layer.close(parent.layer.getFrameIndex(window.name));
                        });
                    } else {
                        layer.msg(data["message"]);
                    }
                }
            });

            return false;
        });
    })
</script>
</body>
</html>